var t = null, o = require("common/common.js");

Page({
    data: {
        f_title: o.config.appData.f_title,
        s_title: o.config.appData.s_title,
        BannerAd: o.config.BannerAd
    },
    onLoad: function(t) {
        this.first(), this.ads();
    },
    onShow: function() {
        this.getpoints();
    },
    first: function() {
        var t = this;
        wx.getStorage({
            key: "day_one_1",
            fail: function(t) {
                wx.setStorage({
                    key: "day_one_1",
                    data: 0
                });
            }
        }), wx.getStorage({
            key: "day_one_2",
            fail: function(t) {
                wx.setStorage({
                    key: "day_one_2",
                    data: 0
                });
            }
        }), wx.getStorage({
            key: "points",
            fail: function(o) {
                wx.setStorageSync("points", 3), t.getpoints(), t.points_history();
            }
        });
    },
    points_history: function() {
        var t = this, n = o.nowTime();
        wx.getStorage({
            key: "points_history",
            fail: function(o) {
                t.setData({
                    list_url: {
                        date: n,
                        content: "初次使用",
                        points: "+3"
                    }
                });
                var a = [ t.data.list_url ], a = JSON.stringify(a);
                wx.setStorage({
                    key: "points_history",
                    data: a
                });
            }
        });
    },
    ads: function() {
        var n = this;
        wx.createRewardedVideoAd && ((t = wx.createRewardedVideoAd({
            adUnitId: o.config.VideoAd
        })).onLoad(), t.onError(function(t) {}), t.onClose(function(t) {
            t && t.isEnded ? n.add_2() : wx.showModal({
                title: "温馨提示",
                content: "中途退出无法获得积分奖励哦",
                success: function(t) {
                    t.confirm ? n.openad() : t.cancel && console.log("用户点击取消");
                }
            });
        }));
    },
    openad: function() {
        t ? t.show() : wx.showModal({
            title: "温馨提示",
            content: "您目前微信版本有误，暂不支持观看"
        });
    },
    getpoints: function() {
        var t = this, o = wx.getStorageSync("points");
        t.setData({
            points: o
        });
    },
    points1_history: function() {
        var t = this;
        wx.getStorage({
            key: "points_history",
            success: function(n) {
                var a = JSON.parse(n.data), i = o.nowTime();
                t.setData({
                    list_url: {
                        date: i,
                        content: "打开推荐程序",
                        points: "+1"
                    }
                });
                var e = (e = [ t.data.list_url ]).concat(a), e = JSON.stringify(e);
                wx.setStorage({
                    key: "points_history",
                    data: e
                });
            }
        });
    },
    points2_history: function() {
        var t = this;
        wx.getStorage({
            key: "points_history",
            success: function(n) {
                var a = JSON.parse(n.data), i = o.nowTime();
                t.setData({
                    list_url: {
                        date: i,
                        content: "观看视频",
                        points: "+3"
                    }
                });
                var e = (e = [ t.data.list_url ]).concat(a), e = JSON.stringify(e);
                wx.setStorage({
                    key: "points_history",
                    data: e
                });
            }
        });
    },
    go1: function(t) {
        var n = this;
        wx.navigateToMiniProgram({
            appId: o.config.appData.f_id,
            path: o.config.appData.f_url,
            success: function(t) {
                n.check1();
            },
            fail: function(t) {
                wx.showModal({
                    title: "温馨提示",
                    content: "中途退出无法获得积分奖励哦",
                    success: function(t) {
                        t.confirm ? n.ios() : t.cancel && console.log("用户点击取消");
                    }
                });
            }
        });
    },
    go2: function(t) {
        var n = this;
        wx.navigateToMiniProgram({
            appId: o.config.appData.s_id,
            path: o.config.appData.s_url,
            success: function(t) {
                n.check2();
            },
            fail: function(t) {
                wx.showModal({
                    title: "温馨提示",
                    content: "中途退出无法获得积分奖励哦",
                    success: function(t) {
                        t.confirm ? n.douyin() : t.cancel && console.log("用户点击取消");
                    }
                });
            }
        });
    },
    nowday: function() {
        return new Date().getDate();
    },
    check1: function() {
        var t = this;
        wx.getStorage({
            key: "day_one_1",
            success: function(o) {
                var n = o.data, a = t.nowday();
                n == a ? wx.showToast({
                    title: "今日已领取",
                    icon: "success",
                    duration: 2e3
                }) : (t.add_1(), wx.setStorage({
                    key: "day_one_1",
                    data: a
                }));
            }
        });
    },
    check2: function() {
        var t = this;
        wx.getStorage({
            key: "day_one_2",
            success: function(o) {
                var n = o.data, a = t.nowday();
                n == a ? wx.showToast({
                    title: "今日已领取",
                    icon: "success",
                    duration: 2e3
                }) : (t.add_1(), wx.setStorage({
                    key: "day_one_2",
                    data: a
                }));
            }
        });
    },
    add_2: function() {
        var t = this, o = (o = wx.getStorageSync("points")) + 2;
        wx.setStorageSync("points", o), wx.showToast({
            title: "积分+2",
            icon: "success",
            duration: 2e3
        }), t.getpoints(), t.points2_history();
    },
    add_1: function() {
        var t = this, o = (o = wx.getStorageSync("points")) + 1;
        wx.setStorageSync("points", o), wx.showToast({
            title: "积分+1",
            icon: "success",
            duration: 2e3
        }), t.getpoints(), t.points1_history();
    },
    gohistory: function() {
        wx.navigateTo({
            url: "points_history"
        });
    }
});